package com.chinatsp.onlineapp.ui.violation;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;

import com.chinatsp.onlineapp.R;
import com.chinatsp.onlineapp.base.BaseActivity;
import com.chinatsp.onlineapp.bean.CityList;
import com.chinatsp.onlineapp.presenter.GetHotCityDao;
/**
 * 选择城市
 */
public class SelectCityActivity extends BaseActivity implements View.OnClickListener {

    private EditText edtText;
    private GridView gvList;
    private ImageView ivBack;
    private Button btnOk;
    private GetHotCityDao mGetHotCityDao;

    private String city = null;
    private CityListAdapter cityListAdapter;
    private List<CityList> cityLists;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_city);
        initView();
    }

    private void initView() {
        edtText = (EditText) findViewById(R.id.sv_text);
        gvList = (GridView) findViewById(R.id.gv_list);
        ivBack = (ImageView) findViewById(R.id.iv_back);
        btnOk = (Button) findViewById(R.id.btn_ok);

        cityLists = new ArrayList<CityList>();

        cityLists.add(new CityList("北京市", "京", true));
        cityLists.add(new CityList("天津市", "津", false));
        cityLists.add(new CityList("哈尔滨市", "黑", false));
        cityLists.add(new CityList("沈阳市", "辽", false));
        cityLists.add(new CityList("南京市", "沪", false));
        cityLists.add(new CityList("苏州市", "苏", false));
        cityLists.add(new CityList("杭州市", "浙", false));
        cityLists.add(new CityList("济南市", "鲁", false));
        cityLists.add(new CityList("郑州市", "豫", false));
        cityLists.add(new CityList("武汉市", "鄂", false));
        cityLists.add(new CityList("长沙市", "湘", false));
        cityLists.add(new CityList("广州市", "粤", false));
        cityLists.add(new CityList("深圳市", "深", false));
        cityLists.add(new CityList("重庆市", "渝", false));
        cityLists.add(new CityList("成都市", "川", false));
        cityLists.add(new CityList("西安市", "陕", false));
        
        cityListAdapter = new CityListAdapter(this, cityLists);
        gvList.setAdapter(cityListAdapter);

        mGetHotCityDao = new GetHotCityDao(this, this);
        mGetHotCityDao.getHotList();
        
        ivBack.setOnClickListener(this);
        btnOk.setOnClickListener(this);
        gvList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                for (int i = 0; i < cityLists.size(); i++) {
                    cityLists.get(i).setChecked(false);
                }
                cityLists.get(position).setChecked(true);
                city = cityLists.get(position).getId();
                cityListAdapter.notifyDataSetChanged();
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.btn_ok:
                finish();
                break;
        }
    }
}
